package cn.singlewindow.ha.util.collector.common.util;

import cn.singlewindow.ha.util.collector.integration.component.IntegrationComponent;
import org.springframework.context.ApplicationContext;

import java.util.Map;

public class SpringContextUtils {

    private static ApplicationContext applicationContext;

    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static void setApplicationContext(ApplicationContext applicationContext) {
        SpringContextUtils.applicationContext = applicationContext;
    }

    public static Object getBean(String name) {
        return applicationContext.getBean(name);
    }

    public static Object getBean(Class<?> requiredType) {
        return applicationContext.getBean(requiredType);
    }

    public static <T> Map<String, T> getBeanOfType(Class<T> clzz) {
        return applicationContext.getBeansOfType(clzz);
    }

    public static IntegrationComponent.MyGateway getSendGateway() {
        return applicationContext.getBean(IntegrationComponent.MyGateway.class);
    }
}